package wxdb.metadata;

import java.io.*;

import wxdb.index.btree.BTreeIndex;
import wxdb.ui.Global;

public class IndexInfoMgr {
	
	public static BTreeIndex getIndexInfo(int dbid, String tableName, String fldName){
		String fileName = "metadata/" + Global.findDBName(dbid) + tableName + fldName + ".idx";
		try{
			FileInputStream fis = new FileInputStream(fileName);
			ObjectInputStream ois = new ObjectInputStream(fis);
			return (BTreeIndex)ois.readObject();
		}catch(ClassNotFoundException cnfe){
			cnfe.printStackTrace();
		}catch(IOException ioe){
			ioe.printStackTrace();
		}
		return null;
	}
	
	public static void writeIndexInfo(int dbid, String tableName, String fldName, BTreeIndex index){
		String fileName = "metadata/" + Global.findDBName(dbid) + tableName + fldName + ".idx";
		try{
			FileOutputStream fos = new FileOutputStream(fileName);
			ObjectOutputStream ois = new ObjectOutputStream(fos);
			ois.writeObject(index);
		}catch(IOException ioe){
			ioe.printStackTrace();
		}
	}
}
